﻿using System;
using TechTalk.SpecFlow;
using WatiN.Core;

namespace Testicide_BDD
{
    [Binding]
    public class ManagingProjectsSteps
    {
        private IE _browser;
        public ManagingProjectsSteps()
        {
            _browser = new IE();
        }

        [Given(@"I'm on MyProjects page")]
        public void GivenIMOnMyProjectsPage()
        {
            _browser.GoTo("http://localhost:57662/Project");
        }

        [When(@"I press addNewProject")]
        public void WhenIPressAddNewProject()
        {
            var link = _browser.Link("addNewProject");
            link.Click();
        }

        [When(@"I fill in Name textfield with ""(.*)""")]
        public void WhenIFillInNameTextfieldWith(string p0)
        {
            var txt = _browser.TextField("Name");
            txt.TypeText(p0);
        }

        [When(@"I fill in Url textfield with ""(.*)""")]
        public void WhenIFillInUrlTextfieldWith(string p0)
        {
            var txt = _browser.TextField("Url");
            txt.TypeText(p0);
        }

        [When(@"I press Create")]
        public void WhenIPressCreate()
        {
            var button = _browser.Button("Create");
            button.Click();
        }

        [When(@"I click on project number (.*) from the projects list")]
        public void WhenIClickOnProjectNumberFromTheProjectsList(int p0)
        {
            var link = _browser.Link("projectDetails_"+p0);
            link.Click();
        }

        [Then(@"I should go to the Details page number (.*)")]
        public void ThenIShouldGoToTheDetailsPageNumber(int p0)
        {
            _browser.GoTo("http://localhost:57662/Project/Details/"+p0);
        }

        [When(@"I click on editProject number (.*)")]
        public void WhenIClickOnEditProjectNumber(int p0)
        {
            var link = _browser.Link("editProject_" + p0);
            link.Click();
        }

        [When(@"I press Edit")]
        public void WhenIPressEdit()
        {
            var button = _browser.Button("Edit");
            button.Click();
        }


        [Then(@"I should see ""(.*)"" in MyProjects page")]
        public void ThenIShouldSeeInMyProjectsPage(string p0)
        {
            _browser.GoTo("http://localhost:57662/Project");
            _browser.ContainsText(p0);
        }

        [When(@"I click on deleteProject number  (.*)")]
        public void WhenIClickOnDeleteProjectNumber(int p0)
        {
            var link = _browser.Link("deleteProject_" + p0);
            link.Click();
        }

        [When(@"I press Delete")]
        public void WhenIPressDelete()
        {
            var button = _browser.Button("Delete");
            button.Click();
        }

        [Then(@"I shouldn't see ""(.*)"" in the MyProjects page")]
        public void ThenIShouldnTSeeInTheMyProjectsPage(string p0)
        {
            _browser.GoTo("http://localhost:57662/Project");
            bool x = !(_browser.ContainsText(p0));
        }

        [When(@"I fill in searchtxt textbox with (.*)")]
        public void WhenIFillInSearchtxtTextboxWith(string p0)
        {
            var txt = _browser.TextField("searchtxt");
            txt.TypeText(p0);
        }

        [When(@"I click on searchbtn button")]
        public void WhenIClickOnSearchbtnButton()
        {
            var button = _browser.Button("searchbtn");
            button.Click();
        }

        [Then(@"I should go to the Search page")]
        public void ThenIShouldGoToTheSearchPage()
        {
            _browser.GoTo("http://localhost:57662/Project/Search");
        }

        
        

        [AfterScenario]
        public void ddd()
        {
            _browser.Dispose();
        }
    }
}